<template>
	<view class="purchaseOrder">
		<uni-nav-bar color="#ffffff" background-color="#00aded" :statusBar="true" title="调拨订单" fixed="true" left-icon="left" left-text="返回" @clickLeft="back"></uni-nav-bar>
		<view class="purchaseOrder_top">
			<!-- 搜索 -->
			<!-- 搜索 -->
			<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
		</view>
		<view class="purchaseOrder_main">
			<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
		</view>
		<view class="purchaseOrder_floot"></view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			options: {
				requestUrl: '/api/v1/ams/getProductOrderList?apiId=658',
				requestQuery: {},
				cardSlotList: [
					{
						label: '运输详情',
						icon: 'bars',
						emitEvent: 'transOrderBrowse'
					},
					{
						label: '制订通知单',
						icon: 'wlIcon-xinzeng',
						emitEvent: 'addRequirement'
					}
				],
				columnDataList: [],
				rowDataList: [],
				totalNum: 0
			}
		};
	},
	computed: {
		...mapState('inward', ['text', 'inwardAppointItem'])
	},
	onShow() {
		uni.$emit('onShow', 1);
	},
	mounted() {},
	methods: {
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		onSearch(item) {
			this.options.requestQuery = JSON.parse(JSON.stringify(item));
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		detailBrowse(item) {
			console.log(item);
			console.log('详情');
		},
		transOrderBrowse(item) {
			uni.navigateTo({
				url:
					'/pages/transOrder/inwardTransOrder?params=' +
					JSON.stringify({
						orderId: item.orderId
					})
			});
		},
		async addRequirement(item) {
			const res = await this.$myRequest({
				url: '/api/v1/uc/getRequirementNo',
				data: {
					businessFlag: 'SC'
				}
			}).catch(() => {
				uni.showToast({
					duration: 2000,
					title: '获取通知单号失败',
					icon: 'success'
				});
			});
			if (res.data.status == 'succeed') {
				this.updateInwardAppointItem({ ...res.data.data, ...item });
			} else {
				uni.showToast({
					duration: 2000,
					title: '获取通知单号失败',
					icon: 'success'
				});
			}
			uni.navigateTo({
				url: '/pages/transAppoint/inwardAppointAddWeight?navBarTitle=新增运输需求&type=add'
			});
		},
		//以下是vuex;
		...mapMutations('inward', ['updateInwardAppointItem'])
	}
};
</script>

<style lang="scss" scoped>
.purchaseOrder {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	&_top {
		background-color: #fff;
	}
	&_main {
	}
	&_floot {
		background-color: #fff;
	}
}
</style>
